package com.xinqi.common.core.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.xinqi.common.base.enums.BaseEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 轮播图位置
 *
 * @Author：yyzhen
 * @Package：com.xinqi.common.core.enums
 * @Project：xingqiclass-cloud-plus
 * @name：RotationImagePositionEnum
 * @Date：2023/4/23 12:05
 * @Filename：RotationImagePositionEnum
 */
public enum RotationImagePositionEnum implements BaseEnum {

    /**
     * APP -- 首页置顶轮播图
     */
    TOP_OF_HOMEPAGE("top_of_homepage", "首页置顶轮播图", RotationImageTypeEnum.APP),

    /**
     * PC -- 课程页右侧轮播图
     */
    COURSE_ON_THE_RIGHT("course_on_the_right", "课程页右侧轮播图", RotationImageTypeEnum.PC);

    @Getter(onMethod_ = {@JsonValue})
    private final String code;

    @Getter
    private final String describe;

    @Getter
    private final RotationImageTypeEnum type;

    RotationImagePositionEnum(String code, String describe, RotationImageTypeEnum type) {
        this.code = code;
        this.describe = describe;
        this.type = type;
    }

    @JsonCreator
    public static RotationImagePositionEnum of(String code) {
        return BaseEnum.of(RotationImagePositionEnum.class, code);
    }

    public static List<Map<String, String>> getSelectList(String type) {
        List<Map<String, String>> list = new ArrayList<>();
        for (RotationImagePositionEnum typeEnum : RotationImagePositionEnum.values()) {
            if (Objects.equals(typeEnum.getType().getCode(), type)) {
                Map<String, String> map = new HashMap<>();
                map.put("code", typeEnum.getCode());
                map.put("describe", typeEnum.getDescribe());
                list.add(map);
            }
        }
        return list;
    }
}
